﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SLBehaviourSystem;
using UnityEngine;
using SLAssetSystem;

public class DemoAgent :BehaviourAgent
{

    public List<GameObject> gos;

    public List<GameObject> way;

    public float Radius{ get;set;}

    public GameObject Target  { get; set; }

    public Transform AgentTransform
    {
        get
        {
            return transform;
        }
    }

    public Dictionary<string, ArgumentContainer<bool>> States
    {
        get
        {
            return states;
        }
    }

    private Dictionary<string, ArgumentContainer<bool>> states= new Dictionary<string, ArgumentContainer<bool>>()
        {
            { "isAttacked",new ArgumentContainer<bool>()}
        };

    public void Init(BehaviourTree tree)
    {
        Tree = tree;
        IsEnabled = true;

        //SelectorNode select = new SelectorNode();
        //tree.AddChild(select);

        //    SquenceNode attackedSquence = new SquenceNode();
        //    attackedSquence.Name = "attackedSquence";
        //    attackedSquence.InteruptType = BehaviourInteruptType.InteruptRight;
        //    select.AddChild(attackedSquence);

        //        ConditionNode isAttackedNode = new ConditionNode();
        //        INodeComponent isAttackedComponent = new IsStateComponent();
        //        isAttackedNode.SetComponent(isAttackedComponent);
        //        attackedSquence.AddChild(isAttackedNode);
        //        BehaviourData isAttackedNodeData = new BehaviourData();
        //        isAttackedNodeData.AddData("Key", "isAttacked");
        //        isAttackedNode.BehaviourData = isAttackedNodeData;
        //        ActionNode attackedNode = new ActionNode();
        //        INodeComponent attackedComponent = new AttackedComponent();
        //        attackedNode.SetComponent(attackedComponent);
        //        attackedSquence.AddChild(attackedNode);

        //    SquenceNode searchEnemySquence = new SquenceNode();
        //    searchEnemySquence.Name = "searchEnemySquence";
        //    searchEnemySquence.InteruptType = BehaviourInteruptType.Both;
        //    select.AddChild(searchEnemySquence);

        //        ConditionNode areaSearch = new ConditionNode();
        //INodeComponent areaSearchComponent = new AreaSearchComponent();
        //        areaSearch.SetComponent(areaSearchComponent);
        //        searchEnemySquence.AddChild(areaSearch);
        //        BehaviourData areaSearchData = new BehaviourData();
        //        areaSearchData.AddData("Radius","16");
        //        areaSearch.BehaviourData = areaSearchData;

        //        ActionNode move = new ActionNode();
        //INodeComponent moveComponent = new MoveComponent();
        //        move.SetComponent(moveComponent);

        //        searchEnemySquence.AddChild(move);

        //        SquenceNode attackEnemySquence = new SquenceNode();
        //        attackEnemySquence.InteruptType = BehaviourInteruptType.Both;
        //        attackEnemySquence.Name = "attackEnemySquence";

        //        searchEnemySquence.AddChild(attackEnemySquence);

        //            ConditionNode areaSearch2 = new ConditionNode();
        //INodeComponent areaSearch2Component = new AreaSearchComponent();
        //            areaSearch2.SetComponent(areaSearch2Component);

        //            attackEnemySquence.AddChild(areaSearch2);
        //            BehaviourData areaSearchData2 = new BehaviourData();
        //            areaSearchData2.AddData("Radius", "2");
        //            areaSearch2.BehaviourData = areaSearchData2;

        //            ActionNode attackNode = new ActionNode();
        //INodeComponent attackComponent = new AttackComponent();
        //            attackNode.SetComponent(attackComponent);
        //            attackEnemySquence.AddChild(attackNode);

        //            ActionNode moveByPoints = new ActionNode();
        //INodeComponent moveByPathPointsComponent = new MoveByPathPointsComponent();
        //            moveByPoints.SetComponent(moveByPathPointsComponent);

        //    select.AddChild(moveByPoints);
    }

    private void Start()
    {
    }

    public void Attack(int skillId)
    {
        DebugUtils.Log("Attack");
    }

    public void Stop()
    {
        DebugUtils.Log("Stop");
    }

    public List<GameObject> GetGos()
    {
        return gos;
    }

    public bool IsAcceptAttackEnd()
    {
        DebugUtils.Log("AcceptAttack");
        return isAttackedEnd;
    }

    public List<GameObject> GetPoints()
    {
        return way;
    }

    public float GetDistance(GameObject go)
    {
        return Vector3.Distance(go.transform.position, transform.position);
    }

    public bool isAttackedEnd;

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            states["isAttacked"].Argument = true;
            isAttackedEnd = false;
        }
        else if(Input.GetKeyDown(KeyCode.E))
        {
            states["isAttacked"].Argument = false;
            isAttackedEnd = true;
        }
    }

    public int GetCurTriggerSkillId()
    {
        return 1;
    }

    public bool IsState(string key)
    {
        if (states.ContainsKey(key))
        {
            return states[key].Argument;
        }
        return false;
    }

    public Animator GetAnimator()
    {
        throw new NotImplementedException();
    }

    public string GetAttackTag()
    {
        throw new NotImplementedException();
    }

}